<template>
  <div class="search">
    <DlForm v-bind="searchFormConfig" :formData="formData">
      <template #header>
        <h1 class="header">高级检索</h1>
      </template>
      <template #footer>
        <div class="handle-btn">
          <el-button type="primary" @click="handleResetClick"
            ><el-icon><Refresh /></el-icon>
            <span>重置</span>
          </el-button>
          <el-button type="primary" @click="handleQueryClick"
            ><el-icon><Search /></el-icon>
            <span>搜索</span>
          </el-button>
        </div>
      </template>
    </DlForm>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from "vue";
import DlForm from "@/base-ui/form";
export default defineComponent({
  props: {
    searchFormConfig: {
      type: Object,
      required: true,
    },
  },
  components: {
    DlForm,
  },
  emits: ["resetBtnClick", "queryBtnClick"],
  setup(props, { emit }) {
    //formData中的属性应该动态决定
    const formItems = props.searchFormConfig.formItems;
    const formOriginData: any = {};
    for (const item of formItems) {
      formOriginData[item.field] = "";
    }
    const formData = ref(formOriginData);
    const handleResetClick = () => {
      for (let key in formData.value) {
        formData.value[key] = "";
      }
      emit("resetBtnClick");
    };
    const handleQueryClick = () => {
      emit("queryBtnClick", formData.value);
    };
    return {
      formData,
      handleResetClick,
      handleQueryClick,
    };
  },
});
</script>

<style scoped>
.handle-btn {
  text-align: right;
  padding: 0 50px 20px 0;
}
</style>
